<?php

namespace Web\MainAppBundle\Controller;

use Doctrine\DBAL\Query\QueryBuilder;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
    /**
     * @Route("/app")
     */
    public function indexAction()
    {
        $conns = $this->getDoctrine()->getConnections();
        $qb = new QueryBuilder($conns["default"]);
        $qb->select("course_lesson.*");
        $qb->from("course_lesson");
//        $qb->where("description = 1");
        $rst = $qb->execute()->fetchAll();
        var_dump($rst[0]);
        $qb = new QueryBuilder($conns["default"]);
        $qb->delete("courselessoncontent");
        $qb->execute();
        foreach ($rst as $one) {
            $qb = new QueryBuilder($conns["default"]);
//            $qb->delete("courselessoncontent");
//            $qb->execute();
//            var_dump($one);
//            $qb->update("category");
//            $qb->set("description",$one["description"] + 1);
//            $qb->where("parentId = ".$one["id"]);
//            $qb->execute();
            $qb->insert("courselessoncontent");
            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
            $qb->setValue("courseId",":courseId")->setParameter("courseId",$one["courseId"]);
            $qb->setValue("arrangeId",":arrangeId")->setParameter("arrangeId",0);
            $qb->setValue("title",":title")->setParameter("title",$one["title"]);
            $qb->setValue("info",":info")->setParameter("info",$one["summary"]);
            $qb->setValue("type",":type")->setParameter("type",0);
            $qb->setValue("addTime",":addTime")->setParameter("addTime",$one["createdTime"]);
            $qb->setValue("updateTime",":updateTime")->setParameter("updateTime",$one["updatedTime"]);
            $qb->setValue("status",":status")->setParameter("status",0);
            $qb->setValue("content",":content")->setParameter("content",$one["content"]);
            $qb->setValue("orders",":orders")->setParameter("orders",$one["seq"]);
//            $qb->setValue("uniqueId",":uniqueId")->setParameter("uniqueId",md5(time().uniqid().rand(1,999999)));
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
            $qb->execute();
        }
        echo "test";die;
    }



    public function indexAction_course_bkp()
    {
        $conns = $this->getDoctrine()->getConnections();
        $qb = new QueryBuilder($conns["default"]);
        $qb->select("course_0.*");
        $qb->from("course_0");
//        $qb->where("description = 1");
        $rst = $qb->execute()->fetchAll();
        var_dump($rst[0]);
        foreach ($rst as $one) {
            $qb = new QueryBuilder($conns["default"]);
//            $qb->delete("course");
//            $qb->execute();
//            var_dump($one);
//            $qb->update("category");
//            $qb->set("description",$one["description"] + 1);
//            $qb->where("parentId = ".$one["id"]);
//            $qb->execute();
            $qb->insert("course");
            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
            $qb->setValue("userId",":userId")->setParameter("userId",19);
            $qb->setValue("title",":title")->setParameter("title",$one["title"]);
            $qb->setValue("category",":category")->setParameter("category",$one["categoryId"]);
            $qb->setValue("picCover",":picCover")->setParameter("picCover",str_replace("public:/","/uploads",$one["middlePicture"]));
            $qb->setValue("picMain",":picMain")->setParameter("picMain",str_replace("public:/","/uploads",$one["largePicture"]));
            $qb->setValue("info",":info")->setParameter("info",$one["about"]);
            $qb->setValue("addTime",":addTime")->setParameter("addTime",$one["createdTime"]);
            $qb->setValue("updateTime",":updateTime")->setParameter("updateTime",$one["updatedTime"]);
            $qb->setValue("status",":status")->setParameter("status",0);
            $qb->setValue("uniqueId",":uniqueId")->setParameter("uniqueId",md5(time().uniqid().rand(1,999999)));
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
//            $qb->setValue("id",":id")->setParameter("id",$one["id"]);
            $qb->execute();
        }
        echo "test";die;
    }




    public function indexAction_courseCategory()
    {
        $conns = $this->getDoctrine()->getConnections();
//        var_dump($conns);
        $qb = new QueryBuilder($conns["default"]);
        $qb->select("category.*");
        $qb->from("category");
//        $qb->where("description = 1");
        $rst = $qb->execute()->fetchAll();
        foreach ($rst as $one) {
            $qb = new QueryBuilder($conns["default"]);
//            var_dump($one);
//            $qb->update("category");
//            $qb->set("description",$one["description"] + 1);
//            $qb->where("parentId = ".$one["id"]);
//            $qb->execute();
            $qb->insert("coursecategory");
//            $qb->values($one);
            $qb->setValue("id","?")->setParameter(0,$one["id"]);
            $qb->setValue("name","?")->setParameter(1,$one["name"]);
            $qb->setValue("orders","?")->setParameter(2,$one["weight"]);
            $qb->setValue("parent","?")->setParameter(3,$one["parentId"]);
            $qb->setValue("level","?")->setParameter(4,$one["description"]);
            $qb->execute();
        }
        echo "test";die;
    }
}
